#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <grpcpp/grpcpp.h>
#include "../protos/RobotPose.grpc.pb.h"
#include "../protos/RobotPose.pb.h"
#include "../atomic_include/RobotPose.h"

class RobotPose_Service_Client {
public:
    RobotPose_Service_Client(std::shared_ptr<::grpc::Channel> channel)
        : stub_(::RobotPose_Package::RobotPose_Service::NewStub(channel)){}
    

    RobotResult getRobotPose(const RequestSignal_2& RobotPose_Request_t){
        RobotPose_Package::RequestSignal_2 request;
        
        
        request.set_signal(RobotPose_Request_t.signal);
        
        
        //Received reply data translate to RobotPose_Reply_t; 
        RobotResult RobotPose_Reply_t;
        RobotPose_Package::RobotResult reply;
        ::grpc::ClientContext context;
        ::grpc::Status status = stub_->getRobotPose(&context, request, &reply);
        
        
        RobotPose_Reply_t.robot_id = reply.robot_id();
        
        
        
        RobotPose_Reply_t.x = reply.x();
        
        
        
        RobotPose_Reply_t.y = reply.y();
        
        
        
        RobotPose_Reply_t.z = reply.z();
        
        
        
        RobotPose_Reply_t.roll = reply.roll();
        
        
        
        RobotPose_Reply_t.pitch = reply.pitch();
        
        
        
        RobotPose_Reply_t.yaw = reply.yaw();
        
        
        
        RobotPose_Reply_t.return_type = reply.return_type();
        
        
        if (status.ok()) {
            std::cout << "RobotPose--> getRobotPose : Received server data success " << std::endl;
        } else {
            std::cout << "RobotPose--> getRobotPose :" << status.error_code() << ": " << status.error_message() << std::endl;
        }
        return RobotPose_Reply_t;
    }

    
private:
    std::unique_ptr<::RobotPose_Package::RobotPose_Service::Stub> stub_;
};